package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.StudentDao;
import com.itheima.edu.info.manager.domain.Student;
import com.itheima.edu.info.manager.dao.StudentDao;

public class StudentService {
    private StudentDao studentDao = new StudentDao();

    public boolean addStudent(Student s) {
        //直接添加

        //传递数据层
        return studentDao.addStudent(s);
    }

    //遍历数组查找id
    public int isExists(String id) {
        Student[] students=studentDao.findAllStudent();

        //判断数组中是否有相同id;
        for (int i = 0; i < students.length; i++) {
            if(students[i] !=null && students[i].getId().equals(id)){
                return i;
            }
        }
        //没有找到返回false
        return -1;
    }


    public Student[] findAllStudent(){
        Student[] students = studentDao.findAllStudent();

        for (int i = 0; i < students.length; i++) {
            if(students[i]!=null){
                return students;
            }
        }
        return null;
    }

    public void deleteStudentById(int isExists) {
        studentDao.deleteStudentById(isExists);
    }

    public void updateStudent(int isExists, Student s) {
        studentDao.updateStudent(isExists,s);
    }
}
